// 引入express
import express from 'express'
import { getIPAdress } from './utils/ipConfig.js'
import connectDb from './plugin/db.js'
import initRoute from './router/index.js'
// 创建app
const app = express()
// 静态托管public文件夹，在public下创建一个index.html文件，启动服务时访问http://localhost:8084可以看到页面
app.use('/', express.static('public'))
// 允许express处理json格式数据，否则将不能处理前端传来的json数据
app.use(express.json())

connectDb(app)
initRoute(app)
const host = getIPAdress()
const port = 8125

app.listen(port, host, () => {
  console.log(`http://${host}:${port} has been already started ...`);
})